cmake_minimum_required(VERSION 3.15)

project(waylandpp-demo)

find_package(UkuiWaylandClient REQUIRED)

set(WAYKLAND_PROTOCOL_DIR ${CMAKE_SOURCE_DIR}/protocols)

set(wayland_sources)
ukui_add_wayland_client_protocol(wayland_sources PROTOCOL ${WAYKLAND_PROTOCOL_DIR}/xdg-shell.xml)
ukui_add_wayland_client_protocol(wayland_sources PROTOCOL ${WAYKLAND_PROTOCOL_DIR}/xdg-decoration-unstable-v1.xml INCLUDE xdg-shell.h)
ukui_add_wayland_client_protocol(wayland_sources PROTOCOL ${WAYKLAND_PROTOCOL_DIR}/xdg-dialog-v1.xml INCLUDE xdg-shell.h)

add_executable(${PROJECT_NAME}
    main.cpp
    display.cpp
    window.cpp
    ${wayland_sources}
)

target_link_libraries(${PROJECT_NAME}
    ukui-wayland-client
)

target_include_directories(${PROJECT_NAME}
    PRIVATE
    ${CMAKE_CURRENT_BINARY_DIR}
)

# Debug Build Only
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    find_program(CLANG_FORMAT clang-format)
    if (CLANG_FORMAT)
        if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
            file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/pre-commit
                DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks
                FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
            )
        endif()
    else()
        message(FATAL_ERROR "clang-format not found! It is required to format code.")
    endif()
endif()